#!/usr/local/bin/python3
# -*- coding: UTF-8 -*-
"""
@author:apple
@file:typeDemo01.py
@time:2021/09/17
"""

class_name = 'Person'

class_parents = (object,)

# class Person:
#     ...
#     def __init__(self,name,age):
#         self.name = name
#         self.age = age
#
#     def __str__(self):
#         return f'name:{self.name},age:{self.age}'

class_source = """
def __init__(self,name,age):
    self.name = name
    self.age = age

def __str__(self):
    return f'name:{self.name},age:{self.age}'
"""

class_dict = dict()
exec(class_source, {}, class_dict)

# print(class_dict)

Person = type(class_name, class_parents, class_dict)

print(Person)

class MyMetal(type):
    ...

    # def __init__(self):
    #     ...
    #     #  初始化 类对象
    #
    # def __new__(cls, *args, **kwargs):
    #     ...
    def __new__(cls, *args, **kwargs):
        ...
        print(cls)
        per = super().__new__(cls,*args, **kwargs)
        return per


    def __call__(self, *args, **kwargs):
        """
        创建类实例
        """
        obj = self.__new__(self)
        self.__init__(obj, *args, **kwargs)
        return obj


class Animal(metaclass=MyMetal):
    ...
    def __init__(self):
        ...

    def __new__(cls, *args, **kwargs):
        ...


if __name__ == '__main__':
    pass
    # per = Person('name', 21)
    # print(per)
    animal = Animal()
    # print(Animal.name)
    # print(Animal.name)